JBoss Community Archive (Read Only)

XNIO

Channel Blocking Modes

When using NIO, a channel may operate in a blocking or non-blocking fashion. Non-blocking I/O is achieved in NIO by way of selectors, which are essentially coordination points between multiple channels. However, this API is combersome and difficult to use; as such, XNIO does not use this facility, preferring instead the callback-based listener system.

An XNIO channel is always non-blocking; however, blocking I/O may be simulated by way of the awaitReadable() and awaitWritable() methods, which will block until the channel is expected to be readable or writable without blocking, or until the current thread is interrupted. The ChannelInputStream and ChannelOutputStream classes use this facility by way of a wrapper around the stream channel types with a blocking InputStream or OutputStream for compatibility with APIs which rely on these types.

Because of this mechanism, blocking and non-blocking operations can be intermixed freely and easily. One common pattern, for example, revolves around using blocking operations for write and non-blocking operations for read. Another pattern is to use blocking I/O in both directions, but only for the duration of a request. See also the Channel Utilities section for additional methods which can help with intermixing blocking and non-blocking operations.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 13:59:27 UTC, last content change 2012-07-02 21:45:24 UTC.